package com.clouddot.baipai.presenter;


import com.clouddot.baipai.contract.IClassFragmentContract;
import com.clouddot.baipai.http.entity.response.getClassHonorResponse;
import com.clouddot.baipai.http.entity.response.getClassInfoByIdResponse;
import com.clouddot.baipai.http.entity.response.getClassInfoListResponse;
import com.clouddot.baipai.http.entity.response.getClassMemberResponse;

import org.wxy.sdk.base.impl.BasePresenterImpl;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

public class ClassFragmentPresenter extends BasePresenterImpl<IClassFragmentContract.IView, IClassFragmentContract.IModel> implements IClassFragmentContract.IPresenter {
    public ClassFragmentPresenter(IClassFragmentContract.IView view, IClassFragmentContract.IModel model) {
        super(view, model);
    }

    @Override
    public void getClassInfoList(int type, String TaskType, String ClassId, int pageindex, int pagesize) {
        Subscription subscription = mModel.getClassInfoList("QueryTaskCardPage", TaskType, ClassId, pageindex, pagesize)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<getClassInfoListResponse>() {
                               @Override
                               public void call(getClassInfoListResponse response) {
                                   mView.success(1, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(1, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }


    @Override
    public void getClassHonorList(String ClassId, int pageindex, int pagesize) {
        Subscription subscription = mModel.getClassHonorList("QueryForClassHonorPage", ClassId, pageindex, pagesize)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<getClassHonorResponse>() {
                               @Override
                               public void call(getClassHonorResponse response) {
                                   mView.success(2, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(2, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }

    @Override
    public void getClassMemberList(String ClassId, int pageindex, int pagesize) {
        Subscription subscription = mModel.getClassMemberList("QueryForStudentPage", ClassId, pageindex, pagesize)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<getClassMemberResponse>() {
                               @Override
                               public void call(getClassMemberResponse response) {
                                   mView.success(3, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(3, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }

    @Override
    public void getClassInfoById(String id) {
        Subscription subscription = mModel.getClassInfoById("QueryTaskDetail", id)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<getClassInfoByIdResponse>() {
                               @Override
                               public void call(getClassInfoByIdResponse response) {
                                   mView.success(4, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(4, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }
}
